home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / tools / czesc_3 / phoonsrc / original / dtime.c < prev    next >
C/C++ Source or Header  |  1988-08-27  |  2KB  |  127 lines

  1. #ifndef lint
  2. static char rcsid[] =
  3.     "@(#) $Header: dtime.c,v 1.3 88/08/26 22:29:38 jef Exp $ (LBL)";
  4. #endif
  5.  
  6. /*
  7. ** Copyright (C) 1988 by Jef Poskanzer.
  8. **
  9. ** Permission to use, copy, modify, and distribute this software and its
  10. ** documentation for any purpose and without fee is hereby granted, provided
  11. ** that the above copyright notice appear in all copies and that both that
  12. ** copyright notice and this permission notice appear in supporting
  13. ** documentation.  This software is provided "as is" without express or
  14. ** implied warranty.
  15. */
  16.  
  17. /* dtime.c - extracted from the phoon/libtws package
  18. */
  19.  
  20.  
  21. #include "tws.h"
  22. #include <stdio.h>
  23. #include <sys/types.h>
  24. #include <time.h>
  25. #ifdef  SYS5
  26. extern int  daylight;
  27. extern long timezone;
  28. extern char *tzname[];
  29. #else    SYS5
  30. #include <sys/timeb.h>
  31. #endif    SYS5
  32.  
  33. static struct zone
  34.     {
  35.     char *std;
  36.     char *dst;
  37.     int shift;
  38.     }
  39.     zones[] = {
  40.     "GMT", "BST", 0,
  41.     "EST", "EDT", -5,
  42.     "CST", "CDT", -6,
  43.     "MST", NULL, -7,
  44.     "PST", "PDT", -8,
  45.     "A", NULL, -1,
  46.     "B", NULL, -2,
  47.     "C", NULL, -3,
  48.     "D", NULL, -4,
  49.     "E", NULL, -5,
  50.     "F", NULL, -6,
  51.     "G", NULL, -7,
  52.     "H", NULL, -8,
  53.     "I", NULL, -9,
  54.     "K", NULL, -10,
  55.     "L", NULL, -11,
  56.     "M", NULL, -12,
  57.     "N", NULL, 1,
  58. #ifndef    HUJI
  59.     "O", NULL, 2,
  60. #else    HUJI
  61.     "JST", "JDT", 2,
  62. #endif    HUJI
  63.     "P", NULL, 3,
  64.     "Q", NULL, 4,
  65.     "R", NULL, 5,
  66.     "S", NULL, 6,
  67.     "T", NULL, 7,
  68.     "U", NULL, 8,
  69.     "V", NULL, 9,
  70.     "W", NULL, 10,
  71.     "X", NULL, 11,
  72.     "Y", NULL, 12,
  73.     NULL };
  74.  
  75. long time( );
  76. struct tm *localtime( );
  77.  
  78.  
  79. struct tws *
  80. dtwstime( )
  81.     {
  82.     long clock;
  83.  
  84.     (void) time( &clock );
  85.     return ( dlocaltime( &clock ) );
  86.     }
  87.  
  88.  
  89. struct tws *
  90. dlocaltime( clock )
  91. long *clock;
  92.     {
  93.     register struct tm *tm;
  94. #ifndef SYS5
  95.     struct timeb tb;
  96. #endif not SYS5
  97.     static struct tws tw;
  98.  
  99.     if ( clock == NULL )
  100.     return ( NULL );
  101.     tw.tw_flags = TW_NULL;
  102.  
  103.     tm = localtime( clock );
  104.     tw.tw_sec = tm -> tm_sec;
  105.     tw.tw_min = tm -> tm_min;
  106.     tw.tw_hour = tm -> tm_hour;
  107.     tw.tw_mday = tm -> tm_mday;
  108.     tw.tw_mon = tm -> tm_mon;
  109.     tw.tw_year = tm -> tm_year;
  110.     tw.tw_wday = tm -> tm_wday;
  111.     tw.tw_yday = tm -> tm_yday;
  112.     if ( tm -> tm_isdst )
  113.     tw.tw_flags |= TW_DST;
  114. #ifndef  SYS5
  115.     ftime( &tb );
  116.     tw.tw_zone = -tb.timezone;
  117. #else   SYS5
  118.     tzset( );
  119.     tw.tw_zone = -(timezone / 60);
  120. #endif  SYS5
  121.     tw.tw_flags &= ~TW_SDAY;
  122.     tw.tw_flags |= TW_SEXP;
  123.     tw.tw_clock = *clock;
  124.  
  125.     return ( &tw );
  126.     }
  127.